package com.chookss.home.audit.reimbursement;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.FolderEntity;
import com.chookss.tools.Utils;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.annotations.Nullable;

public class ReimbursementFolderAdapter extends BaseQuickAdapter<FolderEntity, BaseViewHolderEx> {
    private Activity context;
    private int level;//层级
    private ArrayList<String> nameList;//组织排列
    public ReimbursementFolderAdapter(int layoutResId, Activity context, @Nullable List<FolderEntity> data, ArrayList<String> nameList, int level) {
        super(layoutResId, data);
        this.context = context;
        this.nameList = nameList;
        this.level = level;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, FolderEntity entity) {
        TextView tvItemTitle = helper.getView(R.id.tvItemTitle);
        TextView tvInit = helper.getView(R.id.tvInit);
        TextView tvInit2 = helper.getView(R.id.tvInit2);
        View line = helper.getView(R.id.line);
        tvItemTitle.setText(entity.getBaoxiaoTypeCatalogName());
        if(helper.getItemPosition()==getData().size()-1){
            line.setVisibility(View.GONE);
        }else{
            line.setVisibility(View.VISIBLE);
        }
        if (Utils.isNull(entity.getFolderNum())) {
            tvInit.setVisibility(View.GONE);
        } else {
            tvInit.setVisibility(View.VISIBLE);
            tvInit.setText(entity.getFolderNum() + "个科目");
        }
        if (Utils.isNull(entity.getFileNum())) {
            tvInit2.setVisibility(View.GONE);
        } else {
            tvInit2.setVisibility(View.VISIBLE);
            tvInit2.setText(entity.getFileNum() + "个报销类型");
        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Urls.antiShake.check()) {
                    return;
                }
                Intent intent = new Intent(context, ReimbursementTypesActivity.class);
                ArrayList<String> nameNewList = new ArrayList<>();//组织排列
                nameNewList.addAll(nameList);
                nameNewList.add(entity.getBaoxiaoTypeCatalogName());
                intent.putStringArrayListExtra("nameList", nameNewList);
                intent.putExtra("level", (level + 1));
                intent.putExtra("parentCode", entity.getBaoxiaoTypeCatalogCode());
                intent.putExtra("folderNum", entity.getFolderNum());
                context.startActivity(intent);
            }
        });
    }
}
